package com.spring.test.controller;

import com.spring.test.domain.Role;
import com.spring.test.service.RoleService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/role")
@Controller
public class RoleController {

    @Resource
    private RoleService service;

    @RequestMapping("/save")
    //添加角色
    public String save(Role role){

        service.save(role);

        return "redirect:/role/list";
    }

    @RequestMapping("/list")
    //查询角色列表信息
    public ModelAndView list() {
        ModelAndView model = new ModelAndView();

        List<Role> roleList =  service.list();

        model.addObject("roleList",roleList);

        model.setViewName("role-list");

        return model;
    }


}
